#include "mprpcapplication.h"
#include "friend.pb.h"
#include "mprpcchannel.h"
#include <iostream>

int main(int argc, char** argv)
{
    // 整个程序启动以后,想要使用mprpc框架一定要先调用框架的初始化功能
    MprpcApplication::Init(argc, argv);

    // 演示调用远程发布的rpc方法Login
    fixbug::FriendServiceRpc_Stub stub(new MprpcChannel());
    // 编写rpc方法的请求参数
    fixbug::GetFriendsListRequest request;
    request.set_userid(2016);
    // 输出型响应参数
    fixbug::GetFriendsListResponse response;
    /*
    发起rpc方法的调用 
    ==> RpcChannel::CallMethod
    ==> MprpcChannel::CallMethod
    CallMethod集中来做所有rpc方法调用参数的序列化和网络发送
    */
    stub.GetFriendsList(nullptr, &request, &response, nullptr);

    if (0 == response.result().errcode()) {
        std::cout << "rpc GetFriendsList response success!" << std::endl;
        int size = response.friends_size();
        for (int i = 0; i < size; ++i) {
            std::cout << "index: " << (i+1) << " name: " << response.friends(i) << std::endl;
        }
    }
    else {
        std::cout << "rpc GetFriendsList response error: " << response.result().errmsg() << std::endl;
    }
    return 0;
}